/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/17 15:13
  *
  * @file       pd_timer_ic.h
  * @brief      Header file of Timer IC hardware driver.
  *
  * @note       This file contains the Timer IC object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/17     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_TIMER_IC_H
#define JLC_SKY_TIMER_IC_H

#include "pd_timer.h"
#include "pd_timer_ch.h"

struct TimerICVtbl;

/** @defgroup Object properties
  * @{
  */
typedef struct {
    Timer *timer;
    TimerCh *timerChannel;

    uint32_t ICPolarity;
    uint32_t ICActiveInput;
    uint32_t ICPrescaler;
    uint32_t ICFilter;

    // TimerIC virtual table
    struct TimerICVtbl *vptr;
} TimerIC;
/**
 * @}
 */

/** @defgroup Object virtual table definition
  * @{
  */
struct TimerICVtbl {
    void (*init)(const TimerIC *this, uint8_t isPWMI);

    uint32_t (*get_freq)(const TimerIC *this);

    uint32_t (*get_duty)(const TimerIC *this);
};
/**
 * @}
 */

/** @defgroup Object constructor and member function declaration
  * @{
  */
void TimerIC_constructor(TimerIC *this, Timer *timer, TimerCh *timerChannel);
/**
 * @}
 */

/** @defgroup Object virtual table function implementation
  * @{
  */
static inline void TimerIC_init(const TimerIC *this, const uint8_t isPWMI) {
    this->vptr->init(this, isPWMI);
}

static inline uint32_t TimerIC_getFreq(const TimerIC *this) {
    return this->vptr->get_freq(this);
}

static inline uint32_t TimerIC_getDuty(const TimerIC *this) {
    return this->vptr->get_duty(this);
}
/**
 * @}
 */


#endif //JLC_SKY_TIMER_IC_H
